package com.lwm.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lwm.domain.ResponseResult;
import com.lwm.dto.PageParams;
import com.lwm.mapper.InventoryApprovalMapper;
import com.lwm.domain.InventoryApproval;
import com.lwm.service.InventoryApprovalService;
import com.lwm.utils.Code;
import com.lwm.utils.HintMessage;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 入库申请表(InventoryApproval)表服务实现类
 *
 * @author lzl
 * @since 2023-10-17 13:05:00
 */
@Service("inventoryApprovalService")
public class InventoryApprovalServiceImpl implements InventoryApprovalService {
    @Resource
    private InventoryApprovalMapper inventoryApprovalDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public ResponseResult<InventoryApproval> queryById(Long id) {
        InventoryApproval inventoryApproval = inventoryApprovalDao.queryById(id);

        return new ResponseResult<>(Code.GET_OK, HintMessage.GET_OK_HINT, inventoryApproval);
    }

    /**
     * 分页查询
     *
     * @param inventoryApproval 筛选条件
     * @param pageParams      分页对象
     * @return 查询结果
     */
    @Override
    public ResponseResult<PageInfo> queryByPage(InventoryApproval inventoryApproval, PageParams pageParams) {
        PageInfo<InventoryApproval> resultPage = PageHelper.startPage(pageParams.getPage(), pageParams.getSize()).doSelectPageInfo(() -> {
            inventoryApprovalDao.getPage(inventoryApproval);
        });
        return new ResponseResult<>(Code.GET_OK, HintMessage.GET_OK_HINT, resultPage);
    }

    /**
     * 新增数据
     *
     * @param inventoryApproval 实例对象
     * @return 实例对象
     */
    @Override
    public InventoryApproval insert(InventoryApproval inventoryApproval) {
        this.inventoryApprovalDao.insert(inventoryApproval);
        return inventoryApproval;
    }

    /**
     * 修改数据
     *
     * @param inventoryApproval 实例对象
     * @return 实例对象
     */
    @Override
    public ResponseResult update(InventoryApproval inventoryApproval) {
        inventoryApprovalDao.update(inventoryApproval);
        return new ResponseResult(Code.UPDATE_OK, HintMessage.EDIT_OK_HINT);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.inventoryApprovalDao.deleteById(id) > 0;
    }
}
